import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/api/interface/login_api.dart';
import 'package:lcapp/basic/user_info.dart';
import 'package:lcapp/config/const_config.dart';
import 'package:lcapp/model/dialog/confirm.dart';
import 'package:lcapp/model/event/event_bus.dart';
import 'package:lcapp/model/share/custom_share.dart';
import 'package:lcapp/page/drawer_page.dart';
import 'package:lcapp/page/min/min_cancle_account_page.dart';

class SliderMenu extends StatefulWidget {
  const SliderMenu({Key? key}) : super(key: key);

  @override
  _SliderMenuState createState() => _SliderMenuState();
}

class _SliderMenuState extends State<SliderMenu> {

  List menus = [
    {
      "icon":"assets/slider/slider_vip.png",
      "name":"开通会员",
      "routeName":"MinVipPage"
    },
    {
      "icon":"assets/slider/slider_friends.png",
      "name":"邀请好友",
      "routeName":"MinYaoQingFriendsPage"
    },
    {
      "icon":"assets/slider/slider_sys.png",
      "name":"扫一扫",
      "routeName":"MobileScannerPage"
    },
    {
      "icon":"assets/slider/slider_money.png",
      "name":"钱包",
      "routeName":"MinMoneyPage"
    },
    {
      "icon":"assets/slider/slider_ewm.png",
      "name":"个人二维码",
      "routeName":"MinEWMPage"
    },
    // {
    //   "icon":"assets/slider/slider_order.png",
    //   "name":"我的订单",
    //   "routeName":"MinOrdersPage"
    // },
    {
      "icon":"assets/slider/slider_kefu.png",
      "name":"联系客服",
      "routeName":""
    },
    {
      "icon":"assets/slider/slider_yjfk.png",
      "name":"意见反馈",
      "routeName":"MinYjfkPage"
    },
    // {
    //   "icon":"assets/slider/slider_yjfk.png",
    //   "name":"我的举报",
    //   "routeName":"MinJuBaoPage"
    // },
    {
      "icon":"assets/slider/slider_logout.png",
      "name":"退出登录",
      "routeName":""
    },
    // {
    //   "icon":"assets/slider/slider_logout.png",
    //   "name":"注销账号",
    //   "routeName":""
    // },
    // {
    //   "icon":"assets/slider/slider_about.png",
    //   "name":"关于我们",
    //   "routeName":"MinAboutMinPage"
    // },
    {
      "icon":"assets/slider/slider_set.png",
      "name":"设置",
      "routeName":"Setting"
    }
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: menuItems(),
      ),
    );
  }

  List<Widget> menuItems(){
    List<Widget> mws = [];
    for(int i=0;i<menus.length;i++){
      mws.add(menuItem(menus[i]['icon'], menus[i]['name'],menus[i]['routeName'], i));
    }
    mws.add(
      Container(
        margin: EdgeInsets.only(top: 60.w),
        child: Image.asset("assets/slider/slider_logo.png",width: 180.w,),
      )
    );
    return mws;
  }

  Widget menuItem(String icon,String name,String routeName,int index){
    return GestureDetector(
      onTap: (){
        sliderDrawerKey.currentState?.closeSlider();
        eventBus.fire(HomeSliderChangeIndex(isOpen:false));
        dynamic arguments;
        if(name=='退出登录'){
          openConfirm(
            context,
            isTitle: true,
            title: '提示',
            content: '确定退出登录吗',
            succFn: () async{
              await LoginAPI.loginOut();
              clearUserInfo();
              eventBus.fire(LoginState());
            },
          );
          return;
        }else if(name =='个人二维码'){
          arguments = userInfo;
        }else if(name =='我的举报'){
          arguments = {'type':5};
        }else  if(name =='联系客服'){
          // CustomShare().WXChatService();
          return;
        }
       Navigator.of(context).pushNamed(routeName,arguments: arguments);
      },
      child: Container(
        margin: EdgeInsets.only(top: 60.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              child: Image.asset(icon,width: 35.w,),
            ),
            SizedBox(width: 40.w,),
            Container(
              width: 200.w,
              child: Text(name,style: TextStyle(
                color: Color(0xff1C1C2F),
                fontSize: 32.sp,
                fontWeight: FontWeight.w800
              ),),
            )
          ],
        ),
      ),
    );
  }

}
